package Concurrency.AsynTaskExecute;

/**
 * 定时器 固定时延（Fixed Delay）执行定时任务
 * 运行程序发现，第二个任务在第一个任务LongRunningTask执行结束后才执行，第二个任务每1秒执行1次
 */

import java.util.Timer;
import java.util.TimerTask;

public class TimerFixedDealy {
    static class LongRunningTask extends TimerTask {

        @Override
        public void run() {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("LongRunningTask运行5秒之后，结束  long running finished");
        }
    }

    static class FixedDelayTask extends TimerTask {
        static int count = 0;
        @Override
        public void run() {
            System.out.println(count++);
        }
    }

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new LongRunningTask(), 10);
        timer.schedule(new FixedDelayTask(), 100, 1000);
    }
}
